package com.money.tracker.auth.enums;

import cn.hutool.captcha.*;
import com.money.tracker.common.constant.MoneyTrackerConstant;
import com.money.tracker.common.enums.IResponseEnum;
import com.money.tracker.common.exception.MoneyTrackerBizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;


/**
 * <p>
 * 验证码类别
 * <p>
 *
 * @author zhangshuai
 * &#064;@date 2024/09/21
 */
@Getter
@AllArgsConstructor
public enum CaptchaCategoryEnum {

    /**
     * 线段干扰
     */
    LINE(LineCaptcha.class),

    /**
     * 圆圈干扰
     */
    CIRCLE(CircleCaptcha.class),

    /**
     * 扭曲干扰
     */
    SHEAR(ShearCaptcha.class);

    private final Class<? extends AbstractCaptcha> clazz;

    public static AbstractCaptcha getAbstractCaptcha(CaptchaCategoryEnum category) {
        if (Objects.equals(category, LINE)) {
            LineCaptcha captcha = CaptchaUtil.createLineCaptcha(MoneyTrackerConstant.WIDTH, MoneyTrackerConstant.HEIGHT);
            captcha.setBackground(MoneyTrackerConstant.BACKGROUND);
            captcha.setFont(MoneyTrackerConstant.FONT);
            return captcha;
        }
        if (Objects.equals(category, CIRCLE)) {
            CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(MoneyTrackerConstant.WIDTH, MoneyTrackerConstant.HEIGHT);
            captcha.setBackground(MoneyTrackerConstant.BACKGROUND);
            captcha.setFont(MoneyTrackerConstant.FONT);
            return captcha;
        }
        if (Objects.equals(category, SHEAR)) {
            ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(MoneyTrackerConstant.WIDTH, MoneyTrackerConstant.HEIGHT);
            captcha.setBackground(MoneyTrackerConstant.BACKGROUND);
            captcha.setFont(MoneyTrackerConstant.FONT);
            return captcha;
        }
        throw new MoneyTrackerBizException(IResponseEnum.UNAUTHORIZED);
    }

}